﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace stuManage
{
    public partial class stuIndex : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string id = Request.QueryString["id"];
            string strConn = "server=localhost;port=3306;user id=root;password=lxy1756431734;database=student; pooling=true;";
            MySqlConnection conn = new MySqlConnection(strConn);
            conn.Open();//链接数据库  
            DataSet ds = new DataSet();
            string sql = "select name,department,className from student_inf where id = '" + id + "'";
            MySqlCommand com = new MySqlCommand(sql, conn);
            MySqlDataReader dr = com.ExecuteReader();
            dr.Read();
            string name = dr["name"].ToString();
            string department = dr["department"].ToString();
            string className = dr["className"].ToString();
            string HTML = "<p> 学号：" + id + "<br/>姓名：" + name + "<br/>学院：" + department +"<br/>班级："+className +"</p>";
            information.InnerHtml = HTML;

            string commandString = "select course_inf.id as couId,course_inf.name as couName,grade from course_inf, stu_course where stu_id = '" + id + "' and course_inf.id=course_id";

            SqlDataSource1.SelectCommand = commandString;   //指定查询的命令
            GridView1.DataSourceID = SqlDataSource1.ID;     //将数据源绑定到GridView上
            GridView1.DataBind();

        }
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                string lbl = DataBinder.Eval(e.Row.DataItem, "grade").ToString();
                if (lbl.Length > 0)
                {
                    int grade = Convert.ToInt32(lbl);
                    if (grade < 60)
                    {
                        //e.Row.BackColor = Color.Red ; //行颜色
                        e.Row.Cells[2].ForeColor = Color.Red;
                    }
                    else
                        e.Row.Cells[2].ForeColor = Color.LightGreen;

                }

            }

        }
    }
}